﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication1.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UsersController : ControllerBase
    {
        // GET: api/Users
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/Users/5
        [HttpGet("{id}", Name = "Get")]
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Users
        [HttpPost]
        public ActionResult Post([FromBody] UserDTO users)
        {
            return Ok(new { code = 1000, data = "", msg = "登陆成功" });
        }

        // PUT: api/Users/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {

        }

        // DELETE: api/ApiWithActions/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {

        }

        

        [HttpPost,Route("login")]
        public ActionResult Login([FromBody] LoginDTO login)
        {
            var username = login.Username;
            var password = login.Password;
            return Ok(new { code = 1000, data = new { token = "admin-token" }, msg = "登陆成功" });
        }

        [HttpGet("token"), Route("getUserInfo")]
        public ActionResult GetInfo(string token)
        {
            var roleList = new List<string>
            {
                "admin"
            };

            var accessList = new List<string>
            {
                "setting",
                "users",
                "roles",
                "dashboard"
            };

            return Ok(new
            {
                code = 1000,
                data = new
                {
                    name = "一个爱你的人哟",
                    avatar= "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
                    roles = roleList,
                    access = accessList
                },
                msg = "登录成功"
            });
        }
        [HttpPost, Route("logout")]
        public ActionResult Logout()
        {
            return Ok(new { code = 1000, data = "", msg = "返回登录" });
        }
    }
}
